package com.ruoyi.project.wx.api;


import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.project.wx.service.GoodsBargainService;
import com.ruoyi.project.wx.service.OrderBargainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by HP on 2019/7/3.
 */
@Controller
@RequestMapping("/api/goodsBargain")
public class ApiGoodsBargainController {

    @Autowired
    private GoodsBargainService goodsBargainService;
    @Autowired
    private OrderBargainService orderBargainService;

    /*
    * 查询砍价商品列表
    * */
    @ResponseBody
    @RequestMapping("/getBargainGoodsList")
    public R getBargainGoodsList(@RequestBody Map<String,Object> paramMap) {
        try{
            PageInfo<Map<String,Object>> list = goodsBargainService.getBargainGoodsList(paramMap);
            return R.ok().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }

    /*
    * 我的砍价订单列表
    * */
    @ResponseBody
    @RequestMapping("/getOrderBargainList")
    public R getOrderBargainList(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("userId") || StringUtils.isBlank(paramMap.get("userId").toString())
                    ) {
                return R.error("参数错误");
            }
            PageInfo<Map<String,Object>> list = orderBargainService.getOrderBargainList(paramMap);
            return R.ok().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }

    /*
    * 我的砍价-订单详情
    * */
    @ResponseBody
    @RequestMapping("/getOrderBargainById")
    public R getOrderBargainById(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("bargainOrderId") || StringUtils.isBlank(paramMap.get("bargainOrderId").toString())
                    ) {
                return R.error("参数错误");
            }
            Map<String,Object> list = orderBargainService.getOrderBargainById(paramMap);
            return R.ok().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }

    /*
    * 帮忙砍价
    * */
    @ResponseBody
    @RequestMapping("/helpBargain")
    public R helpBargain(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("bargainOrderId") || StringUtils.isBlank(paramMap.get("bargainOrderId").toString())
                || !paramMap.containsKey("userId") || StringUtils.isBlank(paramMap.get("userId").toString())
                    ) {
                return R.error("参数错误");
            }
            return orderBargainService.helpBargain(paramMap);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }






}
